<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{item}}</li>
  </ul>
  <ul>
    <li v-for="a in productArr">{{a}}</li>
  </ul>
  <table border="1">
    <tr>
      <th>序号</th>
      <th>标题</th>
      <th>价格</th>
      <th>库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.count}}</td>
      <td> <button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const productArr = ref([
  {
    title:'苹果',
    price: 100,
    count: 1
  },
  {
    title:'香蕉',
    price: 100,
    count: 1
  },
  {
    title:'橘子',
    price: 100,
    count: 1
  }

    ]);

const del = (index) => {
  productArr.value.splice(index,1);
}
</script>



<style scoped>

</style>